package com.yupi.generator;

import com.yupi.model.MainTemplateConfig;
import freemarker.template.TemplateException;

import java.io.File;
import java.io.IOException;

public class MainGenerator {
    public static void main(String[] args) {
        //创建model
        MainTemplateConfig mainTemplateConfig = new MainTemplateConfig();
        mainTemplateConfig.setAuthor("dingmingjie");
        mainTemplateConfig.setLoop(true);
        mainTemplateConfig.setOutputText("数的总和:");

        //生成
        try {
            doGenerate(mainTemplateConfig);
        } catch (TemplateException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static void doGenerate(Object model) throws TemplateException, IOException {
        String projectPath = System.getProperty("user.dir"); //F:\project\yuzi-generator\yuzi-generator-basic
        //总项目根路径
        File parentFile = new File(projectPath).getParentFile();//F:\project\yuzi-generator
        //输入路径
        String inputpath = new File(parentFile,"yuzi-generator-demo-projects/acm-template").getAbsolutePath();
        String outputPath = projectPath;
        StaticGenerator.copyFilesByHutool(inputpath,outputPath);
        //ftl路径
        String inputDynamicPath = projectPath + File.separator + "src/main/resources/templates/MainTemplate.java.ftl";
        //outputPath
        String outputDynamicPath = projectPath+File.separator+"acm-template/src/com/yupi/acm/MainTemplate.java";
        DynamicGenerator.doGenerate(inputDynamicPath,outputDynamicPath,model);
    }
}
